package com.ruoyi.hr.service.impl.entryexitmanage.retiremanage;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.mapper.SkyMsgAlarmMapper;
import com.ruoyi.hr.mapper.entryexitmanage.quitmanage.QuitManageMapper;
import com.ruoyi.hr.mapper.entryexitmanage.retiremanage.RetireManageMapper;
import com.ruoyi.hr.service.entryexitmanage.retiremanage.RetireManageService;
import com.ruoyi.hr.util.BaseResult;
import com.ruoyi.hr.util.ResultEnum;
import com.ruoyi.hr.util.utils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author yuanwei
 * @explain 员工退休登记
 * @date 2020/4/14
 */
@Service
public class RetireManageServiceImpl implements RetireManageService {

    @Autowired
    private RetireManageMapper retireManageMapper;

    @Autowired
    private QuitManageMapper quitManageMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SkyMsgAlarmMapper skyMsgAlarmMapper;

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findRetireList(Map<String, Object> map) {
        return retireManageMapper.findRetireList(utils.addAuthority(map));
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public Map<String, Object> findRetire(String id) {
        return retireManageMapper.findRetire(id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int updateRetire(Map<String, Object> map) {
        return retireManageMapper.updateRetire(map);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int remove(String ids) {
        String[] idSplit = ids.split(",");
        int num = 0;
        for (String id : idSplit) {
            int count = retireManageMapper.getCheck(id);
            if (count > 0) {
                return 0;
            }
            num = retireManageMapper.remove(id);
            if (num == 0) {
                return 0;
            }
        }
        return num;
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findRetireHistoryList(Map<String, Object> map) {
        return retireManageMapper.findRetireHistoryList(utils.addAuthority(map));
    }
}
